<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: list.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('assignment_list_page_title'));

$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.resizable.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.dialog.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css')
    ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.datepicker.css')
    ;

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.core.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.draggable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.droppable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.resizable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.dialog.js')
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.datepicker.js')
    ;
?>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><?php echo $this->translator('aissgnment_list_breadcump'); ?></span>
</div>

<div class="grid_12 t_a_bottom">
    <div class="grid_9 alpha"><?php echo $this->translator('aissgnment_list_guide'); ?></div>

    <div class="grid_3 omega">
    </div>
</div>

<!-- Search form -->
<form method="post" action="<?php echo $this->url(array(), 'assignment_assignment_list'); ?>" id="searchAssignmentForm">
<div class="grid_12 t_a_bottom">
    <div class="clearfix t_a_bottom">
        <div class="grid_6 alpha">
            <div class="grid_1">&nbsp;</div>
            <div class="grid_4">
                <b><?php echo $this->translator('assignment_filter');?></b>
                <hr />
            </div>

            <div class="clearfix t_a_bottom">
                <div class="grid_6">
                    <label><?php echo $this->translator('assignment_status');?>:</label>
                    <select style="width:170px;" name="assignment_status">
                        <option value="all"><?php echo $this->translator('assignmen_status_all')?></option>
                        <?php foreach ($this->arrSStatus as $status):?>
                        <option <?php if (isset($this->exp['assignment_status']) && $this->exp['assignment_status'] == $status->id) : ?>selected<?php endif; ?> value="<?php echo $status->id;?>"><?php echo $this->translator('assignment_status_'.$status->code);?></option>
                        <?php endforeach;?>
                    </select>
                </div>
            </div>
            <div class="clearfix t_a_bottom">
                <div class="grid_6">
                    <label><?php echo $this->translator('assignment_create_to_date');?>:</label>
                    <input type="text" name="from_create_date" id="from_create_date" style="width:100px" value="<?php echo (isset($this->exp['assignment_create_from_date']))?date('d/m/Y',strtotime($this->exp['assignment_create_from_date'])):null;?>"/>
                    <?php echo $this->translator('assignment_to_date');?> <input type="text" name="to_create_date" id="to_create_date" style="width:100px"  value="<?php echo (isset($this->exp['assignment_create_to_date']))?date('d/m/Y',strtotime($this->exp['assignment_create_to_date'])):null;?>"/>
                </div>
            </div>
            <div class="clearfix t_a_bottom">
                <div class="grid_6">
                    <label><?php echo $this->translator('assignment_due_to_date');?>:</label>
                    <input type="text" name="from_due_date" id="from_due_date" style="width:100px" value="<?php echo (isset($this->exp['assignment_due_from_date']))?date('d/m/Y',strtotime($this->exp['assignment_due_from_date'])):null;?>" />
                    <?php echo $this->translator('assignment_to_date');?> <input type="text" name="to_due_date" id="to_due_date" style="width:100px" value="<?php echo (isset($this->exp['assignment_due_to_date']))?date('d/m/Y',strtotime($this->exp['assignment_due_to_date'])):null;?>" />
                </div>
            </div>
            <div class="clearfix t_a_bottom">
                <div class="grid_6">
                    <label><?php echo $this->translator('assignment_producer');?>:</label>
                    <select style="width:170px;" name="assignment_producer">
                        <option value="all"><?php echo $this->translator('assignmen_status_all')?></option>
                        <?php foreach ($this->arrSProducer as $pro):?>
                        <option <?php if(isset($this->exp['assignment_producer']) && $this->exp['assignment_producer'] == $pro->user_id):?>selected<?php endif;?> value="<?php echo $pro->user_id;?>"><?php echo (trim($pro->full_name))?$pro->full_name:$pro->user_name;?></option>
                        <?php endforeach;?>
                    </select>
                </div>
            </div>
            <div class="clearfix t_a_bottom">
                <div class="grid_6">
                    <label><?php echo $this->translator('assignment_order_id');?>:</label>
                   <input type="text" name="order_invoice" style="width:100px" value="<?php echo (isset($this->exp['order_invoice']))?$this->exp['order_invoice']:null;?>"/>
                </div>
            </div>
        </div>

        <div class="grid_4 omega">
            <div class="grid_4">
                <b><?php echo $this->translator('assignment_sort');?></b>
                <hr />
            </div>

            <div class="clearfix t_a_bottom">
                <div class="grid_4">
                   <input type="checkbox" name="sort_create_date" value="sort_create_date"  <?php if(isset($this->exp['sort_create_date'])):?>checked<?php endif;?> /> <?php echo $this->translator('assignment_create_date');?>
                </div>
            </div>
            <div class="clearfix t_a_bottom">
                <div class="grid_4">
                   <input type="checkbox" name="sort_product_name" value="sort_product_name" <?php if(isset($this->exp['sort_product_name'])):?>checked<?php endif;?> /> <?php echo $this->translator('assignment_product_name');?>
                </div>
            </div>
        </div>
    </div>

    <hr />

    <div class="clearfix t_a_bottom">
        <label>&nbsp;</label>
        &nbsp;&nbsp;<button type="submit"><span><?php echo $this->translator('assignment_list_search_button'); ?></span></button>
    </div>
</div>
</form>
<!--end search form-->

<!-- List of assignment -->
<?php if ($this->numAssignment == 0) : ?>
<div class="grid_12 t_a_bottom">
    <?php echo $this->translator('aissgnment_list_not_found'); ?>
</div>
<?php else : ?>
<div class="grid_12 t_a_ui_data_list_header" style="height:40px; line-height:20px;">
    <div class="grid_2 alpha" style="width:100px;"><?php echo $this->translator('assignment_order_id'); ?></div>
    <div class="grid_2"><?php echo $this->translator('assignment_product_name'); ?></div>
    <div class="grid_2"><?php echo $this->translator('assignment_producer'); ?></div>
    <div class="grid_1"><?php echo $this->translator('assignment_status'); ?></div>
    <div class="grid_2" style="width:100px;"><?php echo $this->translator('assignment_create_date'); ?></div>
    <div class="grid_2"><?php echo $this->translator('assignment_due_date'); ?></div>
    <div class="grid_2 omega"><?php echo $this->translator('assignment_finish_date'); ?></div>
</div>

<div class="grid_12 t_a_bottom" id="articles">
    <?php foreach ($this->assignments as $row) : ?>
    <?php

        /**
        * Handle php code at here
        * ---Get product info
        * ---Get producer info
        * ---Get assigner info
        * ---Get due date
        **/
        $product  = isset($this->arrProduct[$row->assignment_id])?$this->arrProduct[$row->assignment_id]:null;
        $producer = isset($this->arrProducer[$row->assignment_id])?$this->arrProducer[$row->assignment_id]:null;
        $assigner = isset($this->arrAssigner[$row->assignment_id])?$this->arrAssigner[$row->assignment_id]:null;
        /*$dueDate  = isset($this->arrDueDate[$row->assignment_id])?$this->arrDueDate[$row->assignment_id]:null;*/

        $p_name = 'null';
        if($producer){
            $p_name = (trim($producer->full_name))?$producer->full_name:$producer->user_name;
        }

        $as_name = 'null';
        if($assigner){
            $as_name = (trim($assigner->full_name))?$assigner->full_name:$assigner->user_name;
        }

        /**
         *
        **/
        $class = '';

        //echo $row->assignment_due_date.'-'.date('Y-m-d');die;

        if($row->assignment_finish_date == ''){
            if($row->assignment_due_date < date('Y-m-d')){
                $class = 'style="color:red"';
            }
        }
    ?>
    <div id="assignmetnRow_<?php echo $row->assignment_id; ?>" class="clearfix t_a_ui_data_list_content">
        <div class="grid_2 alpha"  style="width:100px;">
            <div>
                <?php echo $row->order_id;?>
            </div>

            <div class="t_a_top t_a_ui_helper_action">
                <?php if ($this->allow('view')) : ?>
                <a href="<?php echo $this->url(array('assignment_id' => $row->assignment_id), 'assignment_assignment_view'); ?>"><?php echo $this->translator('assignment_list_action_view'); ?></a>
                <?php endif; ?>
            </div>
        </div>
        <div class="grid_2"><?php echo ($product)?$product->product_admin_name:null;?></div>
        <div class="grid_2">
            <?php echo $p_name.' (<b>by</b> '.$as_name.')';?>
        </div>
        <div class="grid_1"><?php echo isset($this->arrStatus[$row->assignment_id])?$this->translator('assignment_status_'.$this->arrStatus[$row->assignment_id]):'&nbsp';?></div>
        <div class="grid_2" style="width:100px;"><?php echo $row->assignment_create_date?date('d-m-Y',strtotime($row->assignment_create_date)):'-'; ?></div>
        <div class="grid_2" <?php echo $class;?>><?php echo $row->assignment_due_date?date('d-m-Y', strtotime($row->assignment_due_date)):'-'; ?></div>
        <div class="grid_2 omega"><?php echo $row->assignment_finish_date?date('d-m-Y',strtotime($row->assignment_finish_date)):'-'; ?></div>
    </div>
    <?php endforeach; ?>
</div>

<div class="grid_12 t_a_bottom t_a_paginator">
    <?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions);?>
</div>
<?php endif; ?>

<div id="messageDialog"></div>
<div id="confirmDialog"></div>

<script type="text/javascript">
$(document).ready(function() {
    /**
    * Create datepicker instances
    */
    $('#from_create_date').datepicker({ dateFormat: 'dd/mm/yy' });
    $('#to_create_date').datepicker({ dateFormat: 'dd/mm/yy' });
    $('#from_due_date').datepicker({ dateFormat: 'dd/mm/yy' });
    $('#to_due_date').datepicker({ dateFormat: 'dd/mm/yy' });
});
</script>